<?php
class AdminPage
{


function showHeader($user)
	{
?>
	<html>
	<head>
		<title>Task Management Software ::Admin</title>
		<script type="text/javascript" src="js/dropdowntabs.js"></script>
		<script type="text/javascript" src="jquery/jquery-1.4.2.min.js"></script>
		<script type="text/javascript" src="js/admin.js"></script>
		<script type="text/javascript" src="js/tms.js"></script>
		
		

		<link href="jquery/jquery-ui.css" rel="stylesheet" type="text/css"/>
		
		<script src="jquery/jquery-ui.js"></script>
		<script src="jquery/date.js"></script>


		<link rel="stylesheet" type="text/css" href="css/ddcolortabs.css"/>
		<link rel="stylesheet" href="css/new.css" />
    </head>
	<body>
		<div id="wrapper"><!--wrapper-->
			<div id="header"><!--header-->
				<div id="logo">Task Management
				</div>				
				<div id="homlog">
					<img src="images/home.gif" width="20" height="20"/>
					<a href="logout.php"><img src="images/logout.png" width="20" height="20" border=0/></a>
				</div>
				<div id="user">
				<span style="text-transform:uppercase" >	Logged as :<?php echo $user->getUserName(); ?><br/>User Type : <?php echo $user->getUserType(); ?></span>
				</div>
			</div><!--header-->

<?php
	}

function mainMenu()
{
?>
	<div id="mainmenu" class="mainmenu"><!--mainmenu-->
				
		<div id="colortab" class="ddcolortabs">
			<ul>
				<li><a class="pointer"  onClick="allprojects()"  title="PROJECTS" ><span>PROJECTS</span></a></button></li>
				<li><a class="pointer" onClick="clients()" title="CLIENTS"><span>CLIENTS</span></a></li>	
				<li><a class="pointer" onClick="users()" title="USERS"><span>USERS</span></a></li>	
				<li><a  title="SYSTEM SETTINGS"><span>PROFILE</span></a></li>	
			</ul>
		</div>

	</div><!--mainmenu-->
	<div class="submenu" id="submenu"><!--headmenu-->

		<div id="tasks">PROJECTS</div>
		<div id="task_buttons">
						
			<button id="addProject" onClick="addproject()">Add Project</button>
			<button id="editProject"  >Edit Project</button>
			<button id="delete">Delete Project</button>
			<button id="addUser" style="display:none" onClick="addUser()">Add User</button>
			<button id="deleteUser" style="display:none" >Delete User</button>
			<button id="addClient" style="display:none" onClick="addClient()">Add Client</button>
			<button id="addModule" style="display:none">Add Module</button>
			<button id="deleteClient" style="display:none">Delete Client</button>
			
		</div>
	</div><!--headmenu-->

<?php

}

function filterMenu()
	{
	?>
<div id="filter"><!--filter-->
			<span>
				Search : 
				<input type="text" maxlength="100" size="25" name="search" id="searchString" />
				<input type="submit" value="Search" />
				<input type="reset" value="Reset" id="resetButton" />
			</span>
			<span style="margin-top:5px;display:block;">
				Filter by : 
				<span id='statusDrop' style='display:none' >
					<select name="status" >
						<option value='0'>--STATUS--</option>
						<option value='1'>ACTIVE</option>
						<option value='2'>INACTIVE</option>
					</select>
				</span>
								
				<span id='desigDrop' style='display:none' >
					<select id="desig">
						<option>--DESIGNATION--</option>
						<option value='1'>DEVELOPER</option>
						<option value='2'>PROJECT_LEADER</option>
						<option value='3'>TESTER</option>
						<option value='4'>ADMIN</option>
							
					</select>
				</span>
					

							<?php

								$ut=User::getDesignation();
								echo "<span id='userTypeDrop' style='display:none'  >". TMSFunctions::generateSelectFromDb($ut,'tms_designation','id','designation','id','','--USER_TYPE--','','','','usertype')."</span>";
									
												$cl=Client::getClients();
												$cliNames="--CLIENTS--";
												$cliValues="--CLIENTS--";
												foreach($cl as $c)
												{
													$cliNames.=",";
													$cliValues.=",";
																	
													$cliNames.=Client::getClientNameFromId($c);
													$cliValues.=$c;
												}
									echo "<span id='clientDrop'  >" .TMSFunctions::generateSelect($cliNames,$cliValues,"","client","sorty(this);","", "clientcheck")."</span>";
							?>
			</span>
					
		</div><!--filter-->



	<?php
	}
function footer()
	{
	?>
<div id="footer">
		&copy CMM Technologies Pvt Ltd
	</div>
</div><!--wrapper-->
</body>
</html>
<?php
	}

function showProjectTable($project)
	{
?>
			



		<table id="project" cellpadding="0" cellspacing="0" >
			<tr>
				<th><input type="checkbox" onclick='toggleCheck(this)' /></th>
				<th>Projects</th>
				<th id="des">Description</th>
				<th>Client</th>
				<th>Start Date</th>
				<th>Deadline</th>
				<th>End date</th>
			</tr>

<?php

		
			if(sizeof($project)==0)
			{
				echo "<tr><td colspan='8'>No Projects Found ....... !</td></tr>";
			}
			else
			{
				foreach($project as $p)
				{
					$pr= new Project($p);
						echo "<tr>";
						echo "<td><input type='checkbox' id='$p' name='tcheckbox'  /></td>";
						echo "<td><a class='pointerlink' name='projId' id='$p' onClick='project($p)'>".$pr->getProjectName()."</td>";
						echo "<td>".$pr->getDescription(). "</td>";
						echo "<td>".Client::getClientNameFromId($pr->getClientId()). "</td>";
						echo "<td>".$pr->getStartingDate(). "</td>";
						echo "<td>".$pr->getDeadline(). "</td>";
						if($pr->getEndingDate()=="")
							echo"<td> Not Completed </td>";
						else
						echo "<td>".$pr->getEndingDate(). "</td>";
						echo "</tr>";
				}
			}
?>
		</table>
<?php
	}


function showModuleTable($pid)
{
?>
		<table id="module" cellpadding="0" cellspacing="0" >
			<tr>
				<th><input type="checkbox" onclick='toggleCheck(this)'/></th>
				<th>Modules</th>
			</tr>

<?php

			$proj=new project($pid);
			$modules=$proj->getModules();


			if(sizeof($modules)==0)
			{
				echo "<tr><td colspan='8'>No Modules Found ....... !</td></tr>";
			}
			else
			{
				foreach($modules as $m)
				{
						echo "<tr>";
						echo "<td><input type='checkbox' id='$p' name='tcheckbox' /></td>";
						echo "<td><a class='pointer' name='$module' id='$module' onClick='project($p)'>".
							TMSFunctions::getModuleNameFromId($m)."</td>";
						echo "</tr>";
				}
			}
?>
		</table>
		<?php
}
function getClientsTable()
	{
		?>
		<table id="clients" cellpadding="0" cellspacing="0" >
			<tr>
				<th><input type="checkbox" onclick='toggleCheck(this)' /></th>
				<th>client Name</th>
				<th>Address</th>
				<th>Email</th>
				<th>Phone Number</th>
				<th>Status</th>
			</tr>

<?php

		  $cl=Client::getClients();

			foreach($cl as $c)
			{
				$cli=new Client($c);
 
				echo"<tr>";
				echo"<td><input type='checkbox' id='$c' name='tcheckbox' /></td>";
				echo"<td>".$cli->getClientName()."</td>";
				echo"<td>".$cli->getAddress()."</td>";
				echo"<td>".$cli->getEmail()."</td>";
				echo"<td>".$cli->getPhoneNumber()."</td>";
				echo"<td>".$cli->getStatus()."</td>";
				echo"</tr>";
			}


	}


function showUsersTable()
	{
?>
		<table id="users" cellpadding="0" cellspacing="0" >
			<tr>
				<th><input type="checkbox" onclick='toggleCheck(this)' /></th>
				<th>First Name</th>
				<th>Last Name</th>
				<th>Email</th>
				<th>Designation</th>
				<th>User Type</th>
				<th>Status</th>

			</tr>

<?php
					
		  $users=User::getUsers();

			foreach($users as $u)
			{
				$us=new User($u);

				echo"<tr>";
				echo"<td><input type='checkbox' id='$u' name='tcheckbox' /></td>";
				echo"<td>".$us->getFirstName()."</td>";
				echo"<td>".$us->getLastName()."</td>";
				echo"<td>".$us->getEmail()."</td>";
				echo"<td>".TMSFunctions::getDesignationFromId($us->getDesignationId())."</td>";
				echo"<td>".$us->getUserType()."</td>";
				echo"<td>".$us->getStatus()."</td>";
				echo"</tr>";
			}





	}


function addProjectTable()
	{
	 $cl=Client::getClients();
		?>
		
			<table id="addproject"  align=center cellpadding=5 cellspacing=5 style="width:60%">
			<th colspan='2'>ADD PROJECT</th>
		<tr>
			<td>Project Name<input type="text" name="pname" id="projectName" maxlength="35" size="35" /></td>
		</tr>

		<tr>
		<td style="vertical-align:top">Description<textarea rows="3" cols="28" id="projectDesc"></textarea></td>
		</tr>

		<tr>
			<td>Client:<?php echo TMSFunctions::generateSelectFromDb($cl,"tms_clients","id","client_name","id","","--Clients--","","","","projectClient");
			?>
			
				Deadline:<input type="text" id="projectDeadline" value="12-12-12">
			</td>
		</tr>
		<tr>
			<td><button onClick="addNewProject()">ADD</button><button onClick="allprojects()">CANCEL</button></td>
		</tr>
		</table>
<?php
	}


function addUserTable()
	{

	$ut=User::getDesignation();
	?>
	
	<table id="addUser"  align=center cellpadding=5 cellspacing=5 style="width:60%">
		<th colspan='2'>ADD MEMBER</th>
		
		<tr>
			<td>First Name</td><td><input type="text" name="firstname" id="firstame" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Last Name</td><td><input type="text" name="lastname" id="lastame" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Username</td><td><input type="text" name="username" id="userName" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Password</td><td><input type="password" name="password" id="password" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Email</td><td><input type="text" name="email" id="email" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Designation</td><td><select id="adddesig">
										<option value='0'>--DESIGNATION--</option>
										<option value='1'>DEVELOPER</option>
										<option value='2'>PROJECT_LEADER</option>
										<option value='3'>TESTER</option>
										<option value='4'>ADMIN</option>
										
									</select></td>
		</tr>
		<tr>
			<td>User Type</td><td><?php echo TMSFunctions::generateSelectFromDb($ut,"tms_designation","id","designation","id","","--USER_TYPE--","","","","addusertype");

		



			?></td>
		</tr>
		<tr>
			<td colspan='2'><button onClick="addNewMember()">ADD</button><button onClick="users()">CANCEL</button></td>
		</tr>
		<?php
}


function addClientTable()
	{

	?>
	
	<table id="addClient"  align=center cellpadding=5 cellspacing=5 style="width:60%">
		<th colspan='2'>ADD CLIENT</th>
		
		<tr>
			<td>Client Name</td><td><input type="text" name="clientname" id="clientname" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Address</td><td><input type="textarea" name="clientaddress" id="clientaddress" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Email</td><td><input type="text" name="clientemail" id="clientemail" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>Phone Number</td><td><input type="text" name="clientnumber" id="clientnumber" maxlength="35" size="35" /></td>
		</tr>
		<tr>
			<td>STATUS</td><td><select id="status">
										<option value='0'>--STATUS--</option>
										<option value='1'>ACTIVE</option>
										<option value='2'>INACTIVE</option>
										
										
									</select></td>
		</tr>
		<tr>
			<td colspan='2'><button onClick="addNewClient()">ADD</button><button onClick="clients()">CANCEL</button></td>
		</tr>
		<?php
}



function editProjectTable($id)
	{
	 $cl=Client::getClients();
	 $p=new Project($id);
		?>
		
			<table id="editproject"  align=center cellpadding=5 cellspacing=5 style="width:60%">
			<th colspan='2'>EDIT PROJECT</th>
		<tr>
			<td>Project Name<input type="text" name="editProname" id="editProjName" value= <?php echo $p->getProjectName(); ?> maxlength="35" size="35" /></td>
		</tr>

		<tr>
		<td style="vertical-align:top">Description<textarea rows="3" cols="28" id="editProjectDesc" ><?php echo $p->getDescription(); ?></textarea></td>
		</tr>

		<tr>
			<td>Client:
			<?php
			$cli=$p->getClientId();
			$client=Client::getClientNameFromId($cli);
			foreach($cl as $c)
			{
				if($c==$cli)
				{
					echo TMSFunctions::generateSelectFromDb($cl,'tms_clients','id','client_name','id',$client,$client,"","","", 'editProjectClient');

				

				}
		}
		
	
			?>
			
				Deadline:<input type="text" id="editProjDeadline" value=<?php echo $p->getDeadline(); ?> />
			</td>
		</tr>
		<tr>
			<td><button onClick="editProject(<?php echo $id; ?>)">EDIT</button><button onClick="allprojects()">CANCEL</button></td>
		</tr>
		</table>
<?php
	}

function project($id)
{
		
	 $p=new Project($id);
	 $members=$p->getMembers();
	 $modules=$p->getModules();
		?>
		
			<table id="project"  align=center cellpadding=5 cellspacing=5 style="width:70%">
			<th colspan='2'><span style="text-transform:uppercase" ><?php echo $p->getProjectName();?></span></th>
		<tr>
			<td><span class="heading">Project Name:</span></td><td><?php echo $p->getProjectName(); ?></td>
		</tr>

		<tr>
		<td ><span class="heading">Description:</span></td><td><?php echo $p->getDescription(); ?></td>
		</tr>

		<tr>
			<td><span class="heading">Client:</span></td>
			<td>
				<?php
				$cli=$p->getClientId();
				echo $client=Client::getClientNameFromId($cli);
				?>
			</td>
		</tr>
		<tr>
			<td>
			
				<span class="heading">Deadline:</span></td><td><?php echo $p->getDeadline();?>
			</td>
		</tr>
		<tr>
			<td><span class="heading">Project Members:</span></td><td><?php 

					foreach($members as $m)
					{
					echo User::getNameByID($m);
					echo "<br>";
					}
					?>
			</td>
		</tr>
		<tr>
			<td><span class="heading">Project Modules:</span></td><td><?php 

					foreach($modules as $mod)
					{
					echo "<a class='pointerlink' id='$mod' onClick='taskTable($mod)'>".TMSFunctions::getModuleNameFromId($mod);
					echo "<br>";
					}
					?>
			</td>
		</tr>
		<tr>
			<td colspan='2'>
				<button onClick="allprojects()">BACK</button>
				<button onClick="addMemberTable(<?php echo $id; ?>)">ADD NEW MEMBER </button>
				<button onClick="addModuleTable(<?php echo $id; ?>)">ADD NEW MODULE</button>
			</td>
		</tr>
		</table>
<?php
}
function addProjectMemberTable($id)
	{
	$u=User::getUsers();
	$p=new Project($id);
	?>
	<table id="addProjectMember"  align=center cellpadding=5 cellspacing=5 style="width:60%">
		<tr>
			<th colspan='2'> <span style="text-transform:uppercase" ><?php echo $p->getProjectName();?>::ADD MEMBER </span></th>
		</tr>
		<tr>
			<td>USER NAME</td><td>
			<?php
				
				echo TMSFunctions::generateSelectFromDb($u,'tms_users','id','username','id','','--USERNAME--','','','','projmember');
				
			?>

			</td>
		</tr>
		<tr>
			<td>MEMBER ROLE</td><td><input type='text' id='memberRole'></td>
			
		</tr>
		<tr>
			<td colspan='2'>
			<button onClick='project(<?php echo $id; ?>)'>BACK</button
			><button onClick="addProjectMember(<?php echo $id; ?>)">ADD</button>
			<button onClick="allprojects()">CANCEL</button></td>
		</tr>
		</table>
<?php

	}

function addProjectModuleTable($id)
	{
		
	$p=new Project($id);
	$mod=new Project($id);
	?>
	<table id="addProjectModule"  align=center cellpadding=5 cellspacing=5 style="width:60%">
		<tr>
			<th colspan='2'> <span style="text-transform:uppercase" ><?php echo $p->getProjectName()?>::ADD MODULE </span></th>
		</tr>
		<tr>
			<td>MODULE NAME</td><td><input type="text" id='newModule'></td>
		</tr>
		<tr>
			<td colspan='2'>
			<button onClick="project(<?php echo $id; ?>)">BACK</button>
			<button onClick="addProjectModule(<?php echo $id; ?>)">ADD</button>
			<button onClick="allprojects()">CANCEL</button></td>
		</tr>
	</table>
<?php	
	}



function taskByModuleTable($mid)
	{
	$pid= TMSFunctions::getProjectIDFromModuleID($mid);
	$task= new Project($mid);
	$tasklist=$task->getTasksByModule($mid);
?>
<table  width="100%" id="taskByModuleTable" cellpadding="0" cellspacing="0" >
<th colspan='9'>
	<span style="text-transform:uppercase" >
		<?php echo Project::getProjectNameById($pid)."-".TMSFunctions::getModuleNameFromId($mid); ?></span></th>
	<tr>
		<th><input type="checkbox" id="maincheckbox" onclick="toggleCheck(this)"/></th>
		<th>Task</th>
		<th>Description</th>
		<th>Start Date</th>
		<th>Due Date</th>
		<th>Priority</th>
		<th>Status</th>
		<th  style="width:10%;line-height:15px" >Percentage Completed</th>
		<th>Assigned to</th>
	</tr>

					<?php
					if(sizeof($tasklist)==0)
					{
						echo "<tr><td colspan='9'>No Records Found....... !</td></tr>";
					}
					else
					{
							foreach($tasklist as $t)
								{						
									$tobj = new Task($t);

									echo "<tr>";
									echo "<td><input type='checkbox' id='$t' name='tcheckbox' /></td>";
									echo "<td>".$tobj->getTaskName()."</td>";
									echo "<td>".$tobj->getTaskDescription()."</td>";
									echo "<td>".$tobj->getTaskStartDate()."</td>";
									echo "<td>".$tobj->getTaskDeadline()."</td>";
									echo "<td>".$tobj->getTaskPriority()."</td>";
									echo "<td>".$tobj->getTaskStatus()."</td>";
									echo "<td>".$tobj->getTaskPercentage()."</td>";
									echo "<td>".TMSFunctions::getUsernameFromId($tobj->getTaskAssignee())."</td>";
									echo "</tr>";
								}
					}
							?>
							<tr>
			<td colspan='9'>
			<button onClick="project(<?php echo TMSFunctions:: getProjectIDFromModuleID($mid); ?>)">BACK</button>
			<button onClick="allprojects()">CANCEL</button></td>
		</tr>
						
						</table>

<?php

	}
}
?>